package com.imc.api.webview.controller;

import com.imc.api.webview.tuple.Airtle;
import com.imc.core.annotation.Logs;
import com.imc.platform.base.notice.dao.INoticeMapper;
import com.imc.platform.base.notice.pojo.Notice;
import com.imc.platform.base.org.service.IOrgService;
import io.netty.util.internal.StringUtil;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;
import java.util.Map;

/**
 * Created by tanweiping on 2018/12/6.
 */
@Controller
@RequestMapping("/api/public/webview")
public class ApiWebviewController {

    @Autowired
    INoticeMapper iNoticeMapper;

    @Autowired
    IOrgService iOrgService;//组织机构服务类

    @Logs
    @GetMapping("/index")
    public String index(
                        Model model,
                        @RequestParam(defaultValue = "airtle") String type,
                        @RequestParam(required = false) String id
                        ){
        Airtle airtle = new Airtle();
        if (type.equals("airtle")&& StringUtils.isNotEmpty(id)){
            Notice notice = iNoticeMapper.queryNoticeById(id);
            if (notice!=null){
                airtle.setTitle(notice.getTitle());
                airtle.setContent(notice.getContent());
            }
            model.addAttribute("airtle",airtle);
        }else
        {
            List<Map<String, Object>> list = iOrgService.queryIntroduceInfo(id, type);
            if (list!=null&&list.size()>0){
                model.addAttribute("airtle",list.get(0));
            }else {
                model.addAttribute("airtle",airtle);
            }
        }
        return "base/webview/index";
    }
}
